package com.IR.order.action;

import java.io.IOException;
import java.io.PrintWriter;
import java.text.ParseException;
import java.util.List;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.stereotype.Controller;

import org.springframework.web.bind.annotation.RequestMapping;

import com.IR.order.service.AOrderBiz;
import com.IR.shop.po.Orderdetail;
import com.IR.shop.po.Orders;
import com.IR.shop.po.Saveorder;
import com.alibaba.fastjson.JSONObject;



@Controller
public class AOrderAction {
	@Resource
	public AOrderBiz biz;
	private Orders orders;
	private Orderdetail orderdetail;
	private List<Orders> list1;
	private List<Orderdetail> list2;
	public Orders getOrders() {
		return orders;
	}
	public void setOrders(Orders orders) {
		this.orders = orders;
	}
	public Orderdetail getOrderdetail() {
		return orderdetail;
	}
	public void setOrderdetail(Orderdetail orderdetail) {
		this.orderdetail = orderdetail;
	}
	public List<Orders> getList1() {
		return list1;
	}
	public void setList1(List<Orders> list1) {
		this.list1 = list1;
	}
	public List<Orderdetail> getList2() {
		return list2;
	}
	public void setList2(List<Orderdetail> list2) {
		this.list2 = list2;
	}
	@RequestMapping(value="/saveOrder1.do")
	public void saveOrder(HttpServletRequest request,HttpServletResponse response) throws ParseException, IOException {
		response.setHeader("Access-Control-Allow-Origin", "*");
		response.setCharacterEncoding("utf-8");
		int siteid=new Integer(request.getParameter("siteid"));
		List<Saveorder> list=JSONObject.parseArray(request.getParameter("order"),Saveorder.class);
		biz.saveOrder2(list,siteid);
		PrintWriter out = response.getWriter();
		out.println(1);		
	}
	/*@RequestMapping(value="/saveOrder2.do")
	public void saveOrder2(HttpServletRequest request,HttpServletResponse response) throws ParseException {
		response.setHeader("Access-Control-Allow-Origin", "*");
		response.setCharacterEncoding("utf-8");
		List<Integer> list=JSONObject.parseArray(request.getParameter("order"),Integer.class);
		biz.saveOrder2(list);		
	}*/
	@RequestMapping(value="/deleteOrderDetail.do")
	public void deleteOrderDetail() {
		biz.deleteOrderDetail();
	}
	@RequestMapping(value="/deleteOrder.do")
	public void deleteOrder() {
		biz.deleteOrder();
	}
	@RequestMapping(value="/updateOrderState.do")
	public void updateOrderState(HttpServletRequest request,HttpServletResponse response) throws IOException {
		response.setHeader("Access-Control-Allow-Origin", "*");
		response.setCharacterEncoding("utf-8");
		Long orderid=new Long(request.getParameter("orderid"));
		int orderstate=new Integer(request.getParameter("orderstate"));
		biz.updateOrderState(orderid,orderstate);
		PrintWriter out = response.getWriter();
		out.println(1);
	}
	@RequestMapping(value="/updateOrderdelete.do")
	public void updateOrderdelete(HttpServletRequest request,HttpServletResponse response) throws IOException {
		response.setHeader("Access-Control-Allow-Origin", "*");
		response.setCharacterEncoding("utf-8");
		Long orderid=new Long(request.getParameter("orderid"));
		biz.updateOrderdelete(orderid);	
		PrintWriter out = response.getWriter();
		out.println(1);
	}
	@RequestMapping(value="/updateOrdertuihuo.do")
	public void updateOrdertuihuo(HttpServletRequest request,HttpServletResponse response) throws IOException {
		response.setHeader("Access-Control-Allow-Origin", "*");
		response.setCharacterEncoding("utf-8");
		Long orderid=new Long(request.getParameter("orderid"));
		biz.updateOrdertuihuo(orderid);		
		PrintWriter out = response.getWriter();
		out.println(1);
	}
	@RequestMapping(value="/updateOrdertuihuo2.do")
	public void updateOrdertuihuo2(HttpServletRequest request,HttpServletResponse response) throws IOException {
		response.setHeader("Access-Control-Allow-Origin", "*");
		response.setCharacterEncoding("utf-8");
		Long orderid=new Long(request.getParameter("orderid"));
		biz.updateOrdertuihuo2(orderid);	
		PrintWriter out = response.getWriter();
		out.println(1);
	}
	@RequestMapping(value="/updateOrderfahuo.do")
	public void updateOrderfahuo(HttpServletRequest request,HttpServletResponse response) throws IOException {
		response.setHeader("Access-Control-Allow-Origin", "*");
		response.setCharacterEncoding("utf-8");
		Long orderid=new Long(request.getParameter("orderid"));
		biz.updateOrderfahuo(orderid);	
		PrintWriter out = response.getWriter();
		out.println(1);
	}
}
